package com.gopay.bis.cuccpay.ebank.impl;

import java.util.Map;

import com.gopay.bis.cuccpay.ebank.operation.CuccPayQuery;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.cuccpay.ebank.CuccPayMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;
import com.gopay.remote.bank.businesses.BankService;

/**
 * 联通沃请求接口
 * 
 * @CuccpayBankServiceImpl.java
 * @author WangHongFei
 */
public class CuccpayBankServiceImpl implements BankService{
	private ICertHelper cuccPayCertHelper = null;
	private CuccPayQuery cuccPayQuery = null;	
	
	public String sign(BaseMessage message) throws GopayException{
		String signStr = cuccPayCertHelper.sign(message);
		return signStr;
	}

	public Object verify(BaseMessage message) throws GopayException{
		boolean verifyResult = false;
		verifyResult = (Boolean) cuccPayCertHelper.verify(message);
		return verifyResult;
	}

	public Object query(Object obj) throws GopayException {
		CuccPayMessage resMessage = null;
		CuccPayMessage queryMsg = (CuccPayMessage) obj;
		String signMsg = (String) cuccPayCertHelper.sign(queryMsg);
		queryMsg.setSignMsg(signMsg);
		Map<String, String> param = cuccPayQuery.buildQueryMsg(queryMsg);// 组装发送订单查询请求信息
		Object resObj = cuccPayQuery.submit(param, queryMsg.getQueryUrl());
		resMessage = cuccPayQuery.parseQueryMsg(resObj,queryMsg.getPrivateKeyPath()); // 返回结果解析
		return resMessage;
	}

	public void setCuccPayCertHelper(ICertHelper cuccPayCertHelper) {
		this.cuccPayCertHelper = cuccPayCertHelper;
	}

	public void setCuccPayQuery(CuccPayQuery cuccPayQuery) {
		this.cuccPayQuery = cuccPayQuery;
	}

	@Override
	public Object dayend(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Object refund(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

}
